/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * This file is part of retabel.
 *
 * Copyright (c) 2011 by individual contributors as indicated by the
 * @author tags. See the copyright.txt file in the distribution
 * for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.retabel.persistence.entity.document;

import javax.persistence.*;
import java.util.Collection;

/**
 * Class description.
 * <p/>
 * <h3>Extra-Info</h3>
 * Created: 21:08 31.07.11
 *
 * @author Burt Parkers
 * @version 1.0
 */
@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"name", "version", "configurationType"}))
@NamedQueries({
    @NamedQuery(name = "DocumentConfiguration.findByNameVersionAndType",
                query = "select documentConfiguration from DocumentConfiguration documentConfiguration where " +
                        "documentConfiguration.name=?1 and documentConfiguration.version=?2 and documentConfiguration.configurationType=?3"),
    @NamedQuery(name = "DocumentConfiguration.findAllByType",
                query = "select documentConfiguration from DocumentConfiguration documentConfiguration " +
                        "where documentConfiguration.configurationType = ?1 " +
                        "order by documentConfiguration.name, documentConfiguration.version"),
    @NamedQuery(name = "DocumentConfiguration.countDocumentConfigurationsByType",
                query = "select count(documentConfiguration) from DocumentConfiguration documentConfiguration where " +
                        "documentConfiguration.configurationType = ?1")
})
public class DocumentConfiguration {

    /** The id field. */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    /** Name of the configuration. */
    @Column(nullable = false, length = 50)
    private String name;

    @Column(nullable = false, length = 10)
    private String version;

    /** section configurationType */
    @Enumerated
    @Column(nullable = false)
    private DocumentConfigurationTypeEnum configurationType = DocumentConfigurationTypeEnum.TEMPORARY;

    @ManyToMany(cascade = {CascadeType.REFRESH, CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn()
    private Collection<SectionConfiguration> sectionConfigurations;

    /**
     * Returns the id.
     *
     * @return the id.
     */
    public int getId() {
        return id;
    }

    /**
     * Sets the id.
     *
     * @param id the id.
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * Returns the name.
     *
     * @return the name.
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name.
     *
     * @param name the name.
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Returns the version.
     *
     * @return the version.
     */
    public String getVersion() {
        return version;
    }

    /**
     * Sets the version.
     *
     * @param version the version.
     */
    public void setVersion(String version) {
        this.version = version;
    }

    /**
     * n
     * Returns the section configurations.
     *
     * @return the section configurations.
     */
    public Collection<SectionConfiguration> getSectionConfigurations() {
        return sectionConfigurations;
    }

    /**
     * Sets the chapter configurations.
     *
     * @param sectionConfigurations the section configurations.
     */
    public void setSectionConfigurations(Collection<SectionConfiguration> sectionConfigurations) {
        this.sectionConfigurations = sectionConfigurations;
    }

    /**
     * Sets the configurationType.
     *
     * @param configurationType The configurationType value to set.
     */
    public void setConfigurationType(DocumentConfigurationTypeEnum configurationType) {
        this.configurationType = configurationType;
    }

    /**
     * Gets the configurationType.
     *
     * @return The configurationType value.
     */
    public DocumentConfigurationTypeEnum getConfigurationType() {
        return configurationType;
    }
}
